var app = angular.module('breadTrip', []);

// 解决jinja2和angular的花括号{{}}冲突的方法
app.config(['$interpolateProvider', function($interpolateProvider) {
    $interpolateProvider.startSymbol('{[');
    $interpolateProvider.endSymbol(']}');
}]);
app.controller('typeController', ['$scope', function($scope){
    var localData = JSON.parse(localStorage.getItem('hotel_'+ BT.context('hotelId') +'_order')) || {};
    $scope.data = obj;
    $scope.selected = localData.product_id;
    var days = Math.abs(moment(BT.context('checkin_date')).diff(BT.context('checkout_date'), "days"));
    $scope.data.filter(function(i, k){
        var fee = parseFloat(i.taxes_and_fees*100/days/100);
        if(fee.toString().split('.').length > 1) fee = fee.toFixed(2);
        i.tax_and_fee = fee;
    })
    $scope.isActive = function(id){
        return $scope.selected == id;
    };
    // tap点击事件 选择房型
    $scope.tapCtrl = function($event, id, name){
        $scope.selected = id;
        localData.product_id = id;
        localData.product_name = name;
        localStorage['hotel_'+BT.context('hotelId') +'_order'] = JSON.stringify(localData);
        var params = location.search.replace(/\?/,'').split('&'), 
            new_array = [],
            url = BT.context('back_url');
        for(var i in params){
            var item = params[i].split('=');
            if(item[0] == 'product_id'){

            }else{
                new_array.push(params[i]);
            }  
        }
        new_array.push('product_id='+ id);
        location.href = url +'?'+ new_array.join('&'); 
    };
}]);